$(function() {


                                           
                                                
                                                  
                                          
                                              


                                            var imgshelfid= configBird("droppic","imgshelf","",400,300,'imgshelf',false,false,"upThumImg");
                                            $("#bookBtn").click(function() {
               
                                                $("#filebirdimage-"+imgshelfid).trigger('click');

                
                                            });

                                            
                                            document.getElementById('pdfdatamultiple').addEventListener('change', handleBirdFiles3, false);
                                            
                                            
                                            configBirdFile("wrapPdf",['pdf','jpg','png','jpeg'],'pdf1[]','application/pdf,image/*','btnAddfile1'); 
                                            configBirdFile("wrapZave",['zave','zavec','zavem','jpg','png','jpeg'],'zavefile[]','application/zave,application/zavec,application/zavem','btnAddfile2,.btnAddfile3,.btnAddfile4',true,['zave','zavec','zavem']);
                                            configBirdFile("wrapMp4",['mp4','jpg','png','jpeg'],'mp4[]','video/mp4,image/*','btnAddfile5'); 

                                            // $("#userlist").kendoMultiSelect().data("kendoMultiSelect"); 
                                             $('#date').datepicker();
                                             $('#date').datepicker("option", "dateFormat", 'dd/mm/yy');
//                                             $('#time').timepicker();
//                                             $('#time2').timepicker();
                                             
                                             
                                           //  $('.dp-choose-date').hide();
   
                                            $('#btnDelfile1').click(function(){
                                               
                                               $("#pdffileload-0").hide();
                                               $('#file2birdsavename-0').val('');
                                               $("#filetarget-0").html("PDF");
                                               
                                            });


                                            $('#btnDelfile2').click(function(){
                                                $("#zavefileload-1").hide();
                                                $('#zavefile2birdsavename-1').val('');
                                                $("#zavefiletarget-1").html("ZAVE");
                                            });


                                           $('.btnDelfile3').click(function(){
                                                $("#zavecfileload-1").hide();
                                                $('#zavecfile2birdsavename-1').val('');
                                                $("#zavecfiletarget-1").html("ZAVEC");
                                            });

                                            $('.btnDelfile4').click(function(){
                                                $("#zavemfileload-1").hide();
                                                $('#zavemfile2birdsavename-1').val('');
                                                $("#zavemfiletarget-1").html("ZAVEM");
                                            });
                                            
                                            $('.btnDelfile5').click(function(){
                                                $("#mp4fileload-2").hide();
                                                $('#file2birdsavename-2').val('');
                                                $("#filetarget-2").html("MP4");
                                            
                                            
                                            });
//                                        
                                        
                                        });

                                        
var widthsidedata=668; 
var widthset=658; 
var widthstart=0;
//var rowpdfadds=2; 
function clickpdfrownow(datasetpdf)
{
$(".dotallpdf").removeClass("dotInA");
var widthclick=0;
$('.dotallpdf').each(function() {

//console.log($(this).attr( "id" ));
//console.log(datasetpdf);
if($(this).attr( "id" )==datasetpdf)
{
  // console.log(widthclick);

  $(".wrapTumbnlDef2").animate({
                                                            left: '-'+widthclick+"px"
                                              }, 700 );
  $(this).addClass("dotInA");

}

widthclick=widthclick+widthsidedata;


});

}
function removedatapdf(rowdeletepdf)
{
var widthclick=0;
var tempwidth=0;
var checkremove=1;
var setnowthis;
$('.dotallpdf').each(function() {

if(($(this).attr( "id" ))=="dotAPpdf"+rowdeletepdf)
{
tempwidth=widthclick;
checkremove=0;

}else
{
if(checkremove==1)
{
setnowthis=this;
}

}
widthclick=widthclick+widthsidedata;

});
tempwidth=tempwidth-widthsidedata;
$(".wrapTumbnlDef2").animate({
                                                            left: '-'+tempwidth+"px"
                                              }, 700 );
$(setnowthis).addClass("dotInA");

$("#wrapPdf"+rowdeletepdf).remove();
$("#dotAPpdf"+rowdeletepdf).remove();
}
function nextdatapdf(rowdeletepdf)
{
var widthclick=0;
var tempwidth=0;
var checkremove=1;
var setnowthis;
$('.dotallpdf').each(function() {

if(($(this).attr( "id" ))=="dotAPpdf"+rowdeletepdf)
{
tempwidth=widthclick;
checkremove=0;
setnowthis=this;

}else
{
if(checkremove==1)
{
//setnowthis=this;
}

}
widthclick=widthclick+widthsidedata;

});

$(".wrapTumbnlDef2").animate({
                                                            left: '-'+tempwidth+"px"
                                              }, 700 );
$('.dotallpdf').removeClass("dotInA");
$(setnowthis).addClass("dotInA");

//$("#wrapZave"+rowdeletezave).remove();
//$("#dotAPzave"+rowdeletezave).remove();
}   
var rowpdfnum=2;                                    
function addpdfform(nonext)
{
var numbtnrow=idmode2+5;
var nowpdf=idmode2;
var code = '<div class="upUIU2" id="wrapPdf'+idmode2+'">\n';

code += '<div class="wrapPdf wrapTmbnlFileType">\n';
code += '<div class="widgetUp">\n';
code += '<div class="wrpWGRG">\n';
code += '<div class="btnClosewg" onclick="addpdfform()"  ></div>\n';
code += '<div class="btnAddwg" onclick="removedatapdf('+idmode2+')"></div>\n';
code += '</div>\n';
code += '<div class="wrpWGThum">\n';
code += '<div class="wrpInnerTmbBook">\n';
code += '<div id="imgfiletarget-'+idmode2+'"><img alt="upimage" src="img/thumnailbookdefault.jpg" class="upThumImg"></div>\n';
code += '<p class="recommendTmbnlBook textUnderTumbnl">300 x 300 px</p>\n';
code += '<button class="btnAddTmbnl btnAddB btnAddfile'+numbtnrow+'">+ Thumbnail</button>\n';
code += '</div>\n';
code += '<input type="text" name="sortfile[]" value="'+rowpdfnum+'" id="pdf-sort-'+idmode2+'" placeholder="Book Order" class="sortWGBO">\n';
code += '<input type="text" placeholder="Document Name" id="pdf-name-'+idmode2+'" name="pdfnamefile[]" class="sortWGDN">\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="wrapInPd">\n';
code += '<div class="tmbnlFileType">\n';
code += '<i class="bookTypeIcon" id="typefiletarget-'+idmode2+'">\n';
code += '<div id="pdffileload-'+idmode2+'" class="load'+idmode2+' loading pdftypeload"></div>\n';
code += '<div class="topRight"></div>\n';
code += '<div class="bottomLeft"></div>\n';
code += '<p class="bookType1 pdftypenow" id="filetarget-'+idmode2+'">PDF</p>\n';
code += '</i>\n';
code += '<button id="btnAddfile'+numbtnrow+'" onclick="return false" class="btnAddfile'+numbtnrow+' btnAddF btnAddB">+ file</button>\n';
code += '<button id="btnDelfile'+numbtnrow+'" onclick="return false" class="btnDelfile'+numbtnrow+' btnAddD btnAddB">-</button>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';

code += '</div>';

$("#pdfloop").append(code);
$("#pdfdotPage").append('<div onclick="clickpdfrownow(\'dotAPpdf'+idmode2+'\')" id="dotAPpdf'+idmode2+'" class="dotOutA dotallpdf"></div>');
//widthstart=widthstart+widthsidedata;
var widthchartnow=widthstart;

                                          //   idmode2++
    $('.wrapTumbnlDef2').width($('.wrapTumbnlDef2').width()+widthset);
    configBirdFile("wrapPdf"+idmode2,['pdf','jpg','png','jpeg'],'pdf1[]','application/pdf,image/*','btnAddfile'+numbtnrow);
    $('#btnDelfile'+numbtnrow).click(function(){
                                               $(".load"+nowpdf).hide();
                                             //  $("#imgfiletarget"+nowpdf).html('<img alt="upimage" src="img/thumnailbookdefault.jpg" class="upThumImg">');
                                               $('#file2birdsavename-'+nowpdf).val('');
                                               $('#file2imgbirdsavename-'+nowpdf).val('');
                                               $("#filetarget-"+nowpdf).html("PDF");
    });
    if(nonext)
    {
    
    }else
    {
    temppdf=idmode2-1;
    nextdatapdf(temppdf);
    }
    rowpdfnum++;
}






var widthsidedata2=668; 
var widthset2=658; 
var widthstart2=0;
function clickmp4rownow(datasetmp4)
{
$(".dotallmp4").removeClass("dotInA");
var widthclick=0;
$('.dotallmp4').each(function() {

//console.log($(this).attr( "id" ));
//console.log(datasetpdf);
if($(this).attr( "id" )==datasetmp4)
{
  // console.log(widthclick);

  $(".wrapTumbnlDef3").animate({
                                                            left: '-'+widthclick+"px"
                                              }, 700 );
  $(this).addClass("dotInA");

}

widthclick=widthclick+widthsidedata2;


});

}
function removedatamp4(rowdeletemp4)
{
var widthclick=0;
var tempwidth=0;
var checkremove=1;
var setnowthis;
$('.dotallmp4').each(function() {

if(($(this).attr( "id" ))=="dotAPmp4"+rowdeletemp4)
{
tempwidth=widthclick;
checkremove=0;

}else
{
if(checkremove==1)
{
setnowthis=this;
}

}
widthclick=widthclick+widthsidedata2;

});
tempwidth=tempwidth-widthsidedata2;
$(".wrapTumbnlDef3").animate({
                                                            left: '-'+tempwidth+"px"
                                              }, 700 );
$(setnowthis).addClass("dotInA");

$("#wrapMp4"+rowdeletemp4).remove();
$("#dotAPmp4"+rowdeletemp4).remove();
}
function nextdatamp4(rowdeletemp4)
{
var widthclick=0;
var tempwidth=0;
var checkremove=1;
var setnowthis;
$('.dotallmp4').each(function() {

if(($(this).attr( "id" ))=="dotAPmp4"+rowdeletemp4)
{
tempwidth=widthclick;
checkremove=0;
setnowthis=this;

}else
{
if(checkremove==1)
{
//setnowthis=this;
}

}
widthclick=widthclick+widthsidedata2;

});

$(".wrapTumbnlDef3").animate({
                                                            left: '-'+tempwidth+"px"
                                              }, 700 );
$('.dotallmp4').removeClass("dotInA");
$(setnowthis).addClass("dotInA");

//$("#wrapZave"+rowdeletezave).remove();
//$("#dotAPzave"+rowdeletezave).remove();
}
var rowmp4num=2;
function addmp4form(nonext)
{
var numbtnrow=idmode2+5;
var nowmp4=idmode2;
var code = '<div class="upUIU2" id="wrapMp4'+idmode2+'">\n';
code += '<div class="wrapPdf wrapTmbnlFileType">\n';
code += '<div class="widgetUp">\n';
code += '<div class="wrpWGRG">\n';
code += '<div class="btnClosewg" onclick="addmp4form()"></div>\n';
code += '<div class="btnAddwg" onclick="removedatamp4('+idmode2+')"></div>\n';
code += '</div>\n';
code += '<div class="wrpWGThum">\n';
code += '<div class="wrpInnerTmbBook">\n';
code += '<div id="imgfiletarget-'+idmode2+'"><img alt="upimage" src="img/thumnailbookdefault.jpg" class="upThumImg"></div>\n';
code += '<p class="recommendTmbnlBook textUnderTumbnl">300 x 300 px</p>\n';
code += '<button class="btnAddTmbnl btnAddB btnAddfile'+numbtnrow+'">+ Thumbnail</button>\n';
code += '</div>\n';
code += '<input type="text" name="sortfile[]" value="'+rowpdfnum+'" id="mp4-sort-'+idmode2+'" placeholder="Book Order" class="sortWGBO">\n';
code += '<input type="text" placeholder="Document Name" id="mp4-name-'+idmode2+'" name="mp4namefile[]" class="sortWGDN">\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="wrapInPd">\n';
code += '<div class="tmbnlFileType">\n';
code += '<i class="bookTypeIcon" id="typefiletarget-'+idmode2+'">\n';
code += '<div id="mp4fileload-'+idmode2+'" class="load'+idmode2+' loading mp4typeload"></div>\n';
code += '<div class="topRight"></div>\n';
code += '<div class="bottomLeft"></div>\n';
code += '<p class="bookType1" id="filetarget-'+idmode2+'">MP4</p>\n';
code += '</i>\n';
code += '<button id="btnAddfile'+numbtnrow+'" onclick="return false" class="btnAddfile'+numbtnrow+' btnAddF btnAddB">+ file</button>\n';
code += '<button id="btnDelfile'+numbtnrow+'" onclick="return false" class="btnDelfile'+numbtnrow+' btnAddD btnAddB">-</button>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';

$("#mp4loop").append(code);
$("#mp4dotPage").append('<div onclick="clickmp4rownow(\'dotAPmp4'+idmode2+'\')" id="dotAPmp4'+idmode2+'" class="dotOutA dotallmp4"></div>');
//widthstart=widthstart+widthsidedata;
var widthchartnow=widthstart2;

                                          //   idmode2++
    $('.wrapTumbnlDef3').width($('.wrapTumbnlDef3').width()+widthset2);
    configBirdFile("wrapMp4"+idmode2,['mp4','jpg','png','jpeg'],'mp4[]','video/mp4,image/*','btnAddfile'+numbtnrow);
    $('#btnDelfile'+numbtnrow).click(function(){
    
                                               $(".load"+nowmp4).hide();
                                               $('#file2birdsavename-'+nowmp4).val('');
                                               $('#file2imgbirdsavename-'+nowmp4).val('');
                                              // $("#imgfiletarget"+nowpdf).html('<img alt="upimage" src="img/thumnailbookdefault.jpg" class="upThumImg">');
                                               $("#filetarget-"+nowmp4).html("MP4");
    });
    if(nonext)
    {
    
    }else
    {
    var tempmp4now=idmode2-1;
    nextdatamp4(tempmp4now);
    }
    rowpdfnum++;
}



var widthsidedata3=668; 
var widthset3=658; 
var widthstart3=0;
function clickzaverownow(datasetzave)
{
$(".dotallzave").removeClass("dotInA");
var widthclick=0;
$('.dotallzave').each(function() {

//console.log($(this).attr( "id" ));
//console.log(datasetpdf);
if($(this).attr( "id" )==datasetzave)
{
  // console.log(widthclick);

  $(".wrapTumbnlDef4").animate({
                                                            left: '-'+widthclick+"px"
                                              }, 700 );
  $(this).addClass("dotInA");

}

widthclick=widthclick+widthsidedata3;


});

}
function removedatazave(rowdeletezave)
{
var widthclick=0;
var tempwidth=0;
var checkremove=1;
var setnowthis;
$('.dotallzave').each(function() {

if(($(this).attr( "id" ))=="dotAPzave"+rowdeletezave)
{
tempwidth=widthclick;
checkremove=0;

}else
{
if(checkremove==1)
{
setnowthis=this;
}

}
widthclick=widthclick+widthsidedata3;

});
tempwidth=tempwidth-widthsidedata3;
$(".wrapTumbnlDef4").animate({
                                                            left: '-'+tempwidth+"px"
                                              }, 700 );
$(setnowthis).addClass("dotInA");

$("#wrapZave"+rowdeletezave).remove();
$("#dotAPzave"+rowdeletezave).remove();
}
function nextdatazave(rowdeletezave)
{
var widthclick=0;
var tempwidth=0;
var checkremove=1;
var setnowthis;
$('.dotallzave').each(function() {

if(($(this).attr( "id" ))=="dotAPzave"+rowdeletezave)
{
tempwidth=widthclick;
checkremove=0;
setnowthis=this;

}else
{
if(checkremove==1)
{
//setnowthis=this;
}

}
widthclick=widthclick+widthsidedata3;

});

$(".wrapTumbnlDef4").animate({
                                                            left: '-'+tempwidth+"px"
                                              }, 700 );
$('.dotallzave').removeClass("dotInA");
$(setnowthis).addClass("dotInA");

//$("#wrapZave"+rowdeletezave).remove();
//$("#dotAPzave"+rowdeletezave).remove();
}
var rowzavenum=2;
function addzaveform(nonext)
{
var numbtnrow=idmode2+5;
var nowzave=idmode2;
var code = '<div class="upUIU2" id="wrapZave'+idmode2+'">\n';
code += '<div class="wrapPdf wrapTmbnlFileType">\n';
code += '<div class="widgetUp">\n';
code += '<div class="wrpWGRG">\n';
code += '<div class="btnClosewg" onclick="addzaveform()"></div>\n';
code += '<div class="btnAddwg" onclick="removedatazave('+idmode2+')"></div>\n';
code += '</div>\n';
code += '<div class="wrpWGThum">\n';
code += '<div class="wrpInnerTmbBook">\n';
code += '<div id="imgfiletarget-'+idmode2+'"><img alt="upimage" src="img/thumnailbookdefault.jpg" class="upThumImg"></div>\n';
code += '<p class="recommendTmbnlBook textUnderTumbnl">300 x 300 px</p>\n';
code += '<button class="btnAddTmbnl btnAddB zavebtnAddfile'+numbtnrow+'">+ Thumbnail</button>\n';
code += '</div>\n';
code += '<input type="text" name="sortfile[]" value="'+rowpdfnum+'" id="zave-sort-'+idmode2+'" placeholder="Book Order" class="sortWGBO">\n';
code += '<input type="text" placeholder="Document Name" id="zave-name-'+idmode2+'" name="zavenamefile[]" class="sortWGDN">\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="wrapInPd">\n';
code += '<div class="tmbnlFileType">\n';
code += '<i class="bookTypeIcon">\n';
code += '<div id="zavefileload-'+idmode2+'" class="zaveload'+idmode2+' loading zavetypeload"></div>\n';
code += '<div class="topRight"></div>\n';
code += '<div class="bottomLeft"></div>\n';
code += '<p class="bookType2 zavetypenow" id="zavefiletarget-'+idmode2+'">ZAVE</p>\n';
code += '</i>\n';
code += '<button id="zavebtnAddfile'+numbtnrow+'" onclick="return false" class="zavebtnAddfile'+numbtnrow+' btnAddF btnAddB">+ file</button>\n';
code += '<button id="zavebtnDelfile'+numbtnrow+'" onclick="return false" class="zavebtnDelfile'+numbtnrow+' btnAddD btnAddB">-</button>\n';
code += '</div>\n';
code += '<div class="tmbnlFileType">\n';
code += '<i class="bookTypeIcon">\n';
code += '<div id="zavecfileload-'+idmode2+'" class="zavecload'+idmode2+' loading zavectypeload"></div>\n';
code += '<div class="topRight"></div>\n';
code += '<div class="bottomLeft"></div>\n';
code += '<p class="bookType2 zavectypenow" id="zavecfiletarget-'+idmode2+'">ZAVEC</p>\n';
code += '</i>\n';
code += '<button id="zavecbtnAddfile'+numbtnrow+'" onclick="return false" class="zavecbtnAddfile'+numbtnrow+' btnAddF btnAddB">+ file</button>\n';
code += '<button id="zavecbtnDelfile'+numbtnrow+'" onclick="return false" class="zavecbtnDelfile'+numbtnrow+' btnAddD btnAddB">-</button>\n';
code += '</div>\n';
code += '<div class="tmbnlFileType">\n';
code += '<i class="bookTypeIcon">\n';
code += '<div id="zavemfileload-'+idmode2+'" class="zavemload'+idmode2+' loading zavemtypeload"></div>\n';
code += '<div class="topRight"></div>\n';
code += '<div class="bottomLeft"></div>\n';
code += '<p class="bookType2 zavemtypenow" id="zavemfiletarget-'+idmode2+'">ZAVEM</p>\n';
code += '</i>\n';
code += '<button id="zavembtnAddfile'+numbtnrow+'" onclick="return false" class="zavembtnAddfile'+numbtnrow+' btnAddF btnAddB">+ file</button>\n';
code += '<button id="zavembtnDelfile'+numbtnrow+'" onclick="return false" class="zavembtnDelfile'+numbtnrow+' btnAddD btnAddB">-</button>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';

$("#zaveloop").append(code);
$("#zavedotPage").append('<div onclick="clickzaverownow(\'dotAPzave'+idmode2+'\')" id="dotAPzave'+idmode2+'" class="dotOutA dotallzave"></div>');
//widthstart=widthstart+widthsidedata;
var widthchartnow=widthstart3;

                                          //   idmode2++
    $('.wrapTumbnlDef4').width($('.wrapTumbnlDef4').width()+widthset3);
    configBirdFile("wrapZave"+idmode2,['zave','zavec','zavem','jpg','png','jpeg'],'zavefile[]','application/zave,application/zavec,application/zavem','zavebtnAddfile'+numbtnrow+',.zavecbtnAddfile'+numbtnrow+',.zavembtnAddfile'+numbtnrow,true,['zave','zavec','zavem']);
    
    
    $('#zavebtnDelfile'+numbtnrow).click(function(){
    
                                               $("#zavefileload-"+nowzave).hide();
                                               $('#zavefile2birdsavename-'+nowzave).val('');
                                               $('#zavefile2imgbirdsavename-'+nowzave).val('');
                                               $("#zavefiletarget-"+nowzave).html("ZAVE");
    });
    
    $('#zavembtnDelfile'+numbtnrow).click(function(){
    
                                               $("#zavemfileload-"+nowzave).hide();
                                               $('#zavemfile2birdsavename-'+nowzave).val('');
                                               $('#zavemfile2imgbirdsavename-'+nowzave).val('');
                                               $("#zavemfiletarget-"+nowzave).html("ZAVEM");
    });
    
    
    $('#zavecbtnDelfile'+numbtnrow).click(function(){
    
                                               $("#zavecfileload-"+nowzave).hide();
                                               $('#zavecfile2birdsavename-'+nowzave).val('');
                                               $('#zavecfile2imgbirdsavename-'+nowzave).val('');
                                               $("#zavecfiletarget-"+nowzave).html("ZAVEC");
    });
    var tempwidth=0;
    
    if(nonext)
    {
    
    }else
    {
    var tempidmode=idmode2-1;
    nextdatazave(tempidmode);
    }
    rowpdfnum++;
}




function resetbanner(rowdataset)
{
var code = '<img id="imgbanner'+rowdataset+'" class="upUIUA" src="img/sceenshotdef2.png" alt="upimage"><div class="upUIUA">\n';
code += '<button id="bannerBtn'+rowdataset+'" class="btnAddUIU btnAddU">+ Screenshot</button>\n';
code += '</div>';
$("#filebirdsavename-"+rowdataset).val('');
$("#droppic"+rowdataset).html(code);
$("#bannerLink-"+rowdataset).val('');

$("#bannerBtn"+rowdataset).click(function() {
               
                $("#filebirdimage-"+rowdataset).trigger('click');

                
                });

}

function savebook()
{

    //console.log($("#userlist").val()); 
   
   
   if($("#topic").val()=="")
    {
     alert("กรุณากรอกหัวข้อการประชุม");
    
    }else if($('input[name="tag[]"]:checked').val()=="")
    {
    
    alert("กรุณาเลือก หน่วยงาน");
    
    }else if($("#title").val()=="")
    {
     alert("กรุณากรอกชื่อประชุม");
    
    }else if($('input[name="tag[]"]:checked').length==0)
    {
     alert("เลือก Tags");
    
    }
    else if($('input[name="cat[]"]:checked').length==0)
    {
     alert("เลือก Book Types");
    
    }else if($("#keyword").val()=="")
    {
     alert("กรุณากรอก Keyword ");
    
    }else if($("#date").val()=="")
    {
     alert("กรุณาเลือกวันที่การประชุม");
    
    }
    
    else if($("#hour1").val()=="")
    {
     alert("กรุณาเลือกช่วงเวลาการประชุม");
    
    }else if($("#min1").val()=="")
    {
     alert("กรุณาเลือกช่วงเวลาการประชุม");
    
    }else if($("#hour2").val()=="")
    {
     alert("กรุณาเลือกช่วงเวลาการประชุม");
    
    }else if($("#min2").val()=="")
    {
     alert("กรุณาเลือกช่วงเวลาการประชุม");
    
    }
    
     else if($("#place").val()=="")
    {
     alert("กรุณาเลือกสถานที่การประชุม");
    
    }
    else if ($("#userlist").val() == '') {
    alert("กรอก Email user");  
    }
    
    else
    {
            
           
            var arrayfile=[];
            var arraytype=[]; 
        

             var pdf1= [];
             var checkpdferror=1;
            $('input[name="pdf1[]"]').each(function(i, el){
                  
                  if($(el).val())
                  {
                  checkpdferror=0;
                  }
                  
                  //pdf1.push( $(el).val() );
                  
                  
            });
            var mp4= [];
            var checkmp4error=1;
            $('input[name="mp4[]"]').each(function(i, el){
                  
                 if($(el).val())
                  {
                  checkmp4error=0;
                  }
                  
                  //mp4.push( $(el).val() );
                  
                  
            });
            
            
          
            
            
            
            if( (checkmp4error==1)&&(checkpdferror==1)&&($("#zavefile2birdsavename-1").val()==""||$("#zavecfile2birdsavename-1").val()==""||$("#zavemfile2birdsavename-1").val()=="") )
            {
            alert("โปรดเลือก File PDF,MP4 หรือ File ZAVE ให้ครบ");
            return false;
            }
             var objdata= [];
             var rowsort=0;
             $('input[name="sortfile[]"]').each(function(i, el){
                  
                 if($(el).val()&&$(el).val()!=0)
                 {
                 objdata.push({key:$(el).attr("id"),value:parseInt($(el).val(),10)});
                 
                // =parseInt($(el).val(),10);
               //  rowsort++;
                 
                 }
                  
                  
                  //mp4.push( $(el).val() );
                  
                  
            });
            var newobjdata= [];
            if(objdata.length>0)
            {
            objdata.sort(function(x,y){return x.value - y.value}); 
            
            
            //console.log(objdata);
            var type=1;
            var krownumdata=1;
            var groupnumdata=1;
            $.each( objdata,function(key, value){
            var n=value.key.split("-"); 
           
            if($('#file2birdsavename-'+n[2]).val()&&$('#'+n[0]+'-name-'+n[2]).val())
            {
            type=1;
            if(n[0]=="mp4")
            {
            type=5;
            
            }
            
            
            newobjdata.push({"file":$('#file2birdsavename-'+n[2]).val(),'group':groupnumdata,"sort":krownumdata,"type":type,"img":$('#file2imgbirdsavename-'+n[2]).val(),"name":$('#'+n[0]+'-name-'+n[2]).val()});
            groupnumdata++;
            }
            else if($("#"+n[0]+"file2birdsavename-"+n[2]).val()&&$("#"+n[0]+"cfile2birdsavename-"+n[2]).val()&&$("#"+n[0]+"mfile2birdsavename-"+n[2]).val()&&$('#'+n[0]+'-name-'+n[2]).val())
            {

                    
            
            newobjdata.push({"file":$('#'+n[0]+'file2birdsavename-'+n[2]).val(),'group':groupnumdata,"sort":krownumdata,"type":2,"img":$('#file2imgbirdsavename-'+n[2]).val(),"name":$('#'+n[0]+'-name-'+n[2]).val()});
            krownumdata++;
            newobjdata.push({"file":$('#'+n[0]+'cfile2birdsavename-'+n[2]).val(),'group':groupnumdata,"sort":krownumdata,"type":3,"img":$('#file2imgbirdsavename-'+n[2]).val(),"name":$('#'+n[0]+'-name-'+n[2]).val()});
            krownumdata++;
             newobjdata.push({"file":$('#'+n[0]+'mfile2birdsavename-'+n[2]).val(),'group':groupnumdata,"sort":krownumdata,"type":4,"img":$('#file2imgbirdsavename-'+n[2]).val(),"name":$('#'+n[0]+'-name-'+n[2]).val()});
            krownumdata++; 
            groupnumdata++;
            
            }
            krownumdata++;
            
            
            
           
            
            });
            
           // console.log(newobjdata);
            
            
            }
        //    return false;
            var checkloader=0;
            $('input[name="sortfile[]"]').each(function(i, el){
            
                    var testcheck=$( this ).attr('id');
                    var indexcheck=testcheck.split('-').pop();
                    if(arraydatamode2[indexcheck]['working2']==1||arraydatamode2[indexcheck]['working1']==1)
                    {
                    checkloader=1;
                    
                    
                    }
            
            
            });
            
            if(checkloader==1)
            {
            
            alert("กรุณารออัพโหลดไฟล์ให้เสร็จ"); 
            
            return false;
            
            }
            
            
            var status=1;
            if($('#status2').is(':checked'))
            {
                  status=2;
            
            }
            
            if(confirm("ต้องการบันทึกใช่หรือไม่"))
            {
            
                 loadsave();
                  var tagid= [];
                  $('input[name="tag[]"]:checked').each(function(i, el){
                  tagid.push( $(el).val() );
                  });
                  
                  
                  var catid= [];
                  $('input[name="cat[]"]:checked').each(function(i, el){
                  catid.push( $(el).val() );
                  });
            
            postCORS(serviceinfo+'savebook',
            {
            photo:$("#filebirdsavename-0").val(),
            title:$("#title").val(),
            description:$("#description").val(),
            tagid:tagid,
            catid:catid,
            keyword:$("#keyword").val(),
            
            
            date:$("#date").val(),
            time:$("#hour1").val()+':'+$("#min1").val(),
            time2:$("#hour2").val()+':'+$("#min2").val(),
            
            place:$("#place").val(),
            userid:$("#userlist").val(), 
            
            shelfid:$("#shelfid").val(),
            bookid:$("#bookid").val(),
            
            topic:$("#topic").val(),
            
            
            
            status:status,
            files:newobjdata
            
            
            } ,function(data) {
            loadclosesave();
            
                        if(data.error)
                      {
                      
                      alert(data.error);
                      }else
                      {
                     location.href=baseinfo+'?shelfid='+$("#shelfid").val();  
                      
                      }
            
            
            });
            
            
            }
    
    }


}

function removebook()
{
if(confirm("ต้องการลบเอกสารทั้งหมดใช่หรือไม่"))
            {
postCORS(serviceinfo+'removebook',
            {
            bookid:$("#bookid").val(),
            shelfid:$("#shelfid").val()
            },function(data) {
                        if(data.error)
                      {
                      
                      alert(data.error);
                      }else
                      {
                      location.href=baseinfo+'?shelfid='+$("#shelfid").val();  
                      
                      }
            
            
            });
            }

}

